<?php defined('SYSPATH') OR die('No direct access allowed.');

class Register_Controller extends Home_Controller {
	public function __construct(){
		parent::__construct();
		
		if ($this->auth->logged_in()){
			url::redirect ('/page');
		}
	}
	
	public function index(){
		$this->template = new View($this->template);
		$this->_set_content(3, 0);
		$this->template->form_Register = new View('t_form_register');
		$this->template->render(TRUE);
	}
	private function _set_content($i_Active, $i_Subactive){
		$m_Content = new Content_Model;
		
		$m_Content->get_content($i_Active, $i_Subactive);
		
		//if ($m_Content->a_Content['title'])
		$this->template->title = $m_Content->a_Content['title'];
		if ($m_Content->a_Content['main_menu']) $this->template->main_menu = $m_Content->a_Content['main_menu'];
		if ($m_Content->a_Content['submenu']) $this->template->sub_menu = $m_Content->a_Content['submenu'];
		if ($m_Content->a_Content['submenu']) $this->template->sub_title = $m_Content->a_Content['submenu'][$i_Subactive]['name'];
	}
	
	public function register(){
		//$this->template = new View($this->template);
		//$this->template->form_Register = new View('t_form_register');
		$m_FormRegister = new Form_Register_Model;
		
		$a_FormRegisterData = $m_FormRegister->receive_data();
		
		if (isset($a_FormRegisterData['info'])){
			//url::redirect('/register/success');
			$this->template = new View($this->template);
			$this->_set_content(3,0);
			$this->template->form_Register = $a_FormRegisterData['info'];
			$this->template->render(TRUE);
		}
		else {
			$this->template = new View($this->template);
			$this->_set_content(3, 0);
			$this->template->form_Register = new View('t_form_register');
			
			$this->template->form_Register->o_Post = $a_FormRegisterData->as_array();
			
			$this->template->render(TRUE);
			//$this->index();
			/*foreach ($a_FormRegisterData['errors'] as $lol){
				echo $lol;
			}*/
		}
	}
	/*public function success(){
		$this->template = new View($this->template);
		$this->_set_content(3,0);
		$this->template->info = 'Registration successful! ';
		$this->template->render(TRUE);
	}*/
}
?>